package com.bkbw.live.battle.net.codec;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import com.bkbw.live.common.dataproto.BattleToDatabasePb.BS2DBCharacterReq;
import com.bkbw.live.common.dataproto.BattleToDatabasePb.DB2BSCharacterResp;
import com.bkbw.live.common.dataproto.ClientToBattleServerPb.*;
//import com.bkbw.live.common.dataproto.BattleToDatabasePb;

public class PackageHead{
	
	public static Map<Short,String> map = new HashMap<>();
	
	static{
		//通过proto文件去反射
		map.put((short)HeadType.DUNGON_LOGIN_REQ_VALUE,LoginReq.class.getName());//进入
		map.put((short)HeadType.DUNGON_LOGIN_RESP_VALUE,LoginResp.class.getName());
		map.put((short)HeadType.DUNGON_PLAYER_MOVE_VALUE,Move.class.getName());//行走
		map.put((short)HeadType.DUNGON_PLAYER_MOVE_STATE_CHANGE_VALUE,MoveStateChange.class.getName());
		map.put((short)HeadType.DUNGON_PLAYER_MOVE_NOTIFY_VALUE,MoveNotify.class.getName());
		map.put((short)HeadType.DUNGON_LOGOUT_VALUE,Logout.class.getName());//离开
		map.put((short)HeadType.DUNGON_LOGOUT_NOTIFY_VALUE,LogoutNotify.class.getName());
		map.put((short)HeadType.DUNGON_LOGIN_NOTIFY_VALUE,LoginNotify.class.getName());
		map.put((short)HeadType.C2BS_BUILD_REQ_VALUE, BuildReq.class.getName());//玩家请求摆放建筑
		map.put((short)HeadType.C2BS_BUILD_REMOVE_REQ_VALUE, BuildRemoveReq.class.getName());//拆除建筑请求
		map.put((short)HeadType.USER_SET_ATTACKTARGET_REQ_VALUE, UserSetAttackTargetReq.class.getName());//拆除建筑请求
		map.put((short)HeadType.C2BS_BUY_ITEM_REQ_VALUE, C2BSBuyItemReq.class.getName());
		map.put((short)HeadType.C2BS_DROP_BAG_ITEM_REQ_VALUE, C2BSDropBagItemReq.class.getName());
		map.put((short)HeadType.C2BS_USE_BAG_ITEM_REQ_VALUE, C2BSUseBagItemReq.class.getName());
		map.put((short)HeadType.C2BS_EQUIP_REQ_VALUE, C2BSEquipReq.class.getName());
		map.put((short)HeadType.C2BS_BAG_ITEM_DETAIL_REQ_VALUE, C2BSBagItemDetailReq.class.getName());
		map.put((short)HeadType.C2BS_BUILD_MOVE_REQ_VALUE, C2BSBuildMoveReq.class.getName());//移动建筑
		//map.put((short)BattleToDatabasePb.HeadType.DB_TABLE_REQ_VALUE, BattleToDatabasePb.TableReq.class.getName());
		// 从db请求玩家信息
		//map.put((short)com.bkbw.live.common.dataproto.BattleToDatabasePb.HeadType.BS2DB_CHARACTER_REQ_VALUE, BS2DBCharacterReq.class.getName());
		
		map.put((short)HeadType.ATTACK_NOTIFY_VALUE,AttackNotify.class.getName());
		map.put((short)HeadType.DAMAGE_NOTIFY_VALUE,DamageNotify.class.getName());
		map.put((short)HeadType.BULLET_CREATE_NOTIFY_VALUE,BulletCreateNotify.class.getName());
		map.put((short)HeadType.BULLET_MOVE_NOTIFY_VALUE,BulletMoveNotify.class.getName());
		map.put((short)HeadType.BULLET_REMOVE_NOTIFY_VALUE,BulletRemoveNotify.class.getName());
		map.put((short)HeadType.BS2C_BUILD_RESP_VALUE, BuildResp.class.getName());//玩家摆放建筑响应结果
		map.put((short)HeadType.BS2C_BUILD_NOTIFY_VALUE, BuildNotify.class.getName());//广播给其他玩家某个建筑被放置在哪里
		map.put((short)HeadType.BS2C_BUILD_REMOVE_RESP_VALUE, BuildRemoveResp.class.getName());//玩家拆除建筑响应结果
		map.put((short)HeadType.BS2C_BUILD_REMOVE_NOTIFY_VALUE, BuildRemoveNotify.class.getName());//广播给其他玩家某个建筑被拆除
		map.put((short)HeadType.BS2C_BUILD_LIST_NOTIFY_VALUE, BuildListNotify.class.getName());//玩家进入房间，把所有建筑信息发给他
		map.put((short)HeadType.BS2C_BUILD_MOVE_RESP_VALUE, BS2CBuildMoveResp.class.getName());//移动建筑响应
		map.put((short)HeadType.BS2C_BUILD_MOVE_NOTIFY_VALUE, BS2CBuildMoveNotify.class.getName());//移动建筑广播
		//map.put((short)BattleToDatabasePb.HeadType.DB_TABLE_RESP_VALUE, BattleToDatabasePb.TableResp.class.getName());
		// 从db获取玩家信息
		//map.put((short)com.bkbw.live.common.dataproto.BattleToDatabasePb.HeadType.DB2BS_CHARACTER_RESP_VALUE, DB2BSCharacterResp.class.getName());
		map.put((short)HeadType.BS2C_BUY_ITEM_RESP_VALUE, BS2CBuyItemResp.class.getName());
		map.put((short)HeadType.BS2C_DROP_BAG_ITEM_RESP_VALUE, BS2CDropBagItemResp.class.getName());
		map.put((short)HeadType.BS2C_USE_BAG_ITEM_RESP_VALUE, BS2CUseBagItemResp.class.getName());
		map.put((short)HeadType.BS2C_EQUIP_RESP_VALUE, BS2CEquipResp.class.getName());
		map.put((short)HeadType.BS2C_BAG_ITEM_DETAIL_RESP_VALUE, BS2CBagItemDetailResp.class.getName());
		map.put((short)HeadType.BS2C_EQUIP_NOTIFY_VALUE, BS2CEquipNotify.class.getName());
		map.put((short)HeadType.BS2C_ADD_MONSTER_NOTIFY_VALUE, AddMonsterNotify.class.getName());
		map.put((short)HeadType.BS2C_REMOVE_MONSTER_NOTIFY_VALUE, RemoveMonsterNotify.class.getName());
	}
	
	/**
	 * 根据消息头来获得传输类的名字
	 * @param head
	 * @return
	 */
	public static String getClassNameByHead(short head){
		return map.get(head);
	}
	
	/**
	 * 根据类名来查找这个类应该匹配哪个消息头
	 * @param name
	 * @return
	 */
	public static short getHeadByClassName(String name){
		Iterator<Short> it = map.keySet().iterator();
		while(it.hasNext()){
			short head = it.next();
			if(map.get(head).equals(name)){
				return head;
			}
		}
		return 0;
	}
}
